home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / CUGUK / PROG_TOO / C013.ZIP / CHMOD.C < prev    next >
Text File  |  1990-01-19  |  2KB  |  66 lines

  1. /********************************************************************
  2.  * C Users Group (U.K) C Source Code Library File CUGLIB.013        *
  3.  * Inquiries to: M. Houston, 36 Whetstone Clo. Farquhar Rd.         *
  4.  * Edgbaston, Birmingham B15 2QN ENGLAND                *
  5.  ********************************************************************
  6.  * File name: chmod.c
  7.  * Program name:chmod 
  8.  * Source of file: Ron Wellstead
  9.  * Purpose: An MS-DOS copy of the UNIX utility of the same name.
  10.  * Changes: <who what when & why major changes have been made>      
  11.  ********************************************************************/
  12.  
  13. /*
  14.  *
  15.  *    @(#) chmod.c 1.2 87/07/27 
  16.  *
  17.  *    UNIX style chmod utility for dos
  18.  *
  19.  *    copyright (c) 1987 Ron Wellsted.
  20.  *    This software is provided on the understanding that it is
  21.  *    NOT to be used for commercial gain. It may be freely distributed
  22.  *    in source or object form among amateur and hobby computer users ONLY!
  23.  *
  24.  *    changes mode (write access) of files
  25.  *    usage: chmod {+/-} files....
  26.  *    Written for Microsoft C, link with setargv.obj to expand wildcards
  27.  */
  28. #include    <stdio.h>
  29. #include    <sys/types.h>
  30. #include    <sys/stat.h>
  31. #include    <io.h>
  32.  
  33. char buffer[]="@(#)chmod VR 1.0.0 15 Jul 1987";
  34.  
  35. main(argc,argv)
  36. int argc;
  37. char *argv[];
  38. {
  39.     char *ptr;
  40.     int i,mode;
  41.  
  42.     if (argc>=3)
  43.     {
  44.         ptr=argv[1];
  45.         ptr++;
  46.         if ((*argv[1]=='-')&&(tolower(*ptr)=='w')) mode=S_IREAD;
  47.         else if ((*argv[1]=='+')&&(tolower(*ptr)=='w')) mode=S_IWRITE;
  48.         else mode=0;
  49.     }
  50.     if ((argc<3)||(mode==0))
  51.     {
  52.         fprintf(stderr,"usage: chmod +|-w file1 [.... fileN]\n");
  53.         exit(1);
  54.     }
  55.     for (i=2;i<argc;i++)
  56.     {
  57.         if (chmod(argv[i],mode))
  58.         {
  59.             fprintf(stderr,"chmod: ");
  60.             perror(argv[i]);
  61.             exit(1);
  62.         }
  63.     }
  64.     exit(0);
  65. }
  66.